package org.metis4j.framework.core.impl;

import java.lang.annotation.Annotation;
import java.util.List;

import org.metis4j.framework.core.ClassScanner;
import org.metis4j.framework.core.impl.support.AbsAnnotationClassTemplate;
import org.metis4j.framework.core.impl.support.AbsClassTemplate;
import org.metis4j.framework.core.impl.support.AbsSuperClassTemplate;
import org.metis4j.framework.util.ClassUtil;
import org.slf4j.IMarkerFactory;

public class DefaultClassScanner implements ClassScanner {

	public List<Class<?>> getClassList(String packageName) {
		// TODO Auto-generated method stub
		return new AbsClassTemplate(packageName) {
			@Override
			public boolean checkAddClass(Class<?> clazz) {
				// TODO Auto-generated method stub
				String className = clazz.getName();
				String pkName = className.substring(0, className.lastIndexOf("."));
				return pkName.startsWith(packageName);
			}
		}.getClassList();
	}

	public List<Class<?>> getClassListByAnnotation(String packageName, Class<? extends Annotation> annotation) {
		// TODO Auto-generated method stub
		return new AbsAnnotationClassTemplate(packageName, annotation) {
			@Override
			public boolean checkAddClass(Class<?> clazz) {
				// TODO Auto-generated method stub
				return clazz.isAnnotationPresent(annotation);
			}
		}.getClassList();
	}

	public List<Class<?>> getClassListBySuper(String packageName, Class superClass) {
		// TODO Auto-generated method stub
		return new AbsSuperClassTemplate(packageName, superClass) {
			@Override
			public boolean checkAddClass(Class<?> clazz) {
				// TODO Auto-generated method stub
				return superClass.isAssignableFrom(clazz) && !superClass.equals(clazz);
			}
		}.getClassList();
	}

}
